<!-- 部门列表 损益分析 -->
<template>
  <div>
    <el-form class="const_top" :model="queryParams" size="small" :inline="true">
      <el-row>
        <el-col :span="24">
          <el-form-item prop="" style="height: 40px">
            <el-select
              v-model="byMonth.relateId"
              placeholder="请选择部门"
              clearable
              @change="deptChange"
            >
              <el-option
                v-for="dict in deptOptions"
                :key="dict.relateId"
                :label="dict.label"
                :value="dict.relateId"
              />
            </el-select>
          </el-form-item>
          <el-form-item prop="" style="height: 40px">
            <el-date-picker
              clearable
              v-model="queryParams.createdTime"
              type="month"
              placeholder="选择月"
              @change="createdTimeChange"
              :disabled="mouday"
            >
            </el-date-picker>
          </el-form-item>
          <el-form-item prop="" style="height: 40px">
            <el-select
              v-model="queryParams.pandianCode"
              placeholder="1号至10号"
              clearable
              :disabled="mount"
            >
              <el-option
                v-for="dict in NewDropDownList"
                :key="dict.value"
                :label="dict.label"
                :value="dict.value"
              />
            </el-select>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" size="mini" @click="handleQuery"
              >查询
            </el-button>
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
    <el-table :data="tableData">
      <el-table-column align="center" label="序号" type="index" width="50">
      </el-table-column>
      <el-table-column label="部门名称" prop="pname" align="center">
      </el-table-column>
      <el-table-column
        v-for="(item, index) in dataOne"
        :key="index"
        :label="item.label"
        :props="item.children ? '' : item.props"
        align="center"
      >
        <template v-if="item.children">
          <el-table-column
            v-for="(ite, ind) in item.children"
            :key="ind"
            :label="ite.label"
            :prop="ite.props"
            align="center"
          ></el-table-column>
        </template>
      </el-table-column>
      <el-table-column label="操作" props="" align="center">
        <template slot-scope="scope">
          <div>
            <el-button size="mini" type="text" @click="Godept(scope.row)"
              >该部门顶级类别损益分析</el-button
            >
          </div>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>

<script>
import { deptAllpage } from "@/api/system/cost";
import { getPanDianCode, FindShopBom } from "@/api/system/stock";
export default {
  props: {
    dataOne: {
      type: Array,
    },
  },
  data() {
    return {
      queryParams: {},
      tableData: [],
      examineOption: [],

      deptOptions: [],
      DropDownList: [],
      NewDropDownList: [],
      tableData: [],
      byMonth: {},
      mouday: true,
      mount: true,
      defaultProps: {
        children: "children",
        label: "label",
      },
    };
  },
  created() {
    FindShopBom().then((res) => {
      if (res.code == 200) {
        this.deptOptions = res.data;
      }
    });
  },
  methods: {
    handleQuery() {
      if (this.byMonth.relateId) {
        this.queryParams.shopCode = this.byMonth.relateId;
      }
      deptAllpage(this.queryParams).then((res) => {
        this.tableData = res.data;
      });
    },
    getList() {
      deptAllpage(this.queryParams).then((res) => {
        this.tableData = res.data;
      });
    },
    Godept(v) {
      this.$router.push({
        path: "/SubclassProfit",
        query: {
          pandianCode: this.queryParams.pandianCode,
          shopCode: this.queryParams.shopCode,
          stapType: v.stapType,
        },
      });
    },
    createdTimeChange(v) {
      let data = new Date(v);
      let y = data.getFullYear();
      let m = data.getMonth() + 1;
      this.byMonth.pandianData = y + String(m).padStart(2, "0");

      getPanDianCode(this.byMonth).then((res) => {
        if (res.code == 200) {
          this.DropDownList = res.data;
          this.NewDropDownList = [];
          this.DropDownList.forEach((element) => {
            let label =
              new Date(element.startTime).getDate() +
              "号-" +
              new Date(element.endTime).getDate() +
              "号";
            this.NewDropDownList.push({
              value: element.pandianCode,
              label: label,
            });
          });
          if (res.data != []) {
            this.mount = false;
          }
        }
      });
    },
    deptChange(v) {
      if (v) {
        this.mouday = false;
      } else {
        this.mouday = true;
      }
    },
  },
};
</script>

<style lang="scss" scoped></style>
